package com.icetech.eom.service.impl.tx;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Lists;
import com.icetech.eom.dao.tx.LogDao;
import com.icetech.eom.domain.tx.Log;
import com.icetech.eom.domain.tx.dto.LogExcelDto;
import com.icetech.eom.service.tx.ILogService;
import com.xuxueli.poi.excel.ExcelExportUtil;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wangzw
 * @since 2018-11-12
 */
@Service
public class LogServiceImpl extends ServiceImpl<LogDao, Log> implements ILogService {

    @Autowired
    private LogDao logDao;
    @Override
    public PageInfo<Log> selectByPage(String searchKey, Integer page, Integer pageSize) {
        PageHelper.startPage(page,pageSize);
        List<Log> logs = logDao.selectBySearchKey(searchKey);
        return new PageInfo(logs);
    }

    @Override
    public Workbook exportExcel(String searchKey) {
        List<Log> logs = logDao.selectBySearchKey(searchKey);
        List<LogExcelDto> logExcelDtos = Lists.newArrayList();
        logs.forEach(session -> {
            LogExcelDto sessionExcelDto = new  LogExcelDto();
            BeanUtils.copyProperties(session, sessionExcelDto);
            logExcelDtos.add(sessionExcelDto);
        });
        return ExcelExportUtil.exportWorkbook(logExcelDtos);
    }
}
